package LeetCode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/20.
//
//https://leetcode.cn/problems/length-of-last-word/description/
public class 最后一个单词的长度 {
    public static void main(String[] args) {
        String str = "a ";
        System.out.println(lengthOfLastWord(str));
    }
    public static int lengthOfLastWord(String s) {
        if(!s.contains(" "))return s.length();
        int point = s.length()-1;
        while(s.charAt(point) == ' '){
            point--;
        }
        int num = 0;
        while (point > -1 && s.charAt(point) != ' '){
            num++;
            point--;
        }
        return num;
    }
}
